package com.anrongtec.zcpt.ui.activity.myfocus;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;
import com.anrongtec.zcpt.model.focus.DynamicInfo;
import com.anrongtec.zcpt.model.focus.FocusPeopleInfo;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.anrongtec.zcpt.R.id.tv_focus_people_dynamicInfo_from;

public class FocusPeopleDetailActivity extends BaseActivity {

    @BindView(R.id.iv_focus_people_photo)
    ImageView mIvFocusPeoplePhoto;
    @BindView(R.id.tv_focus_people_name)
    TextView mTvFocusPeopleName;
    @BindView(R.id.tv_focus_people_time)
    TextView mTvFocusPeopleTime;
    @BindView(R.id.tv_focus_people_sex)
    TextView mTvFocusPeopleSex;
    @BindView(R.id.tv_focus_people_nation)
    TextView mTvFocusPeopleNation;
    @BindView(R.id.tv_focus_people_idNum)
    TextView mTvFocusPeopleIdNum;
    @BindView(R.id.tv_focus_people_location)
    TextView mTvFocusPeopleLocation;
    @BindView(R.id.tv_focus_people_type)
    TextView mTvFocusPeopleType;
    @BindView(R.id.tv_focus_people_crimeType)
    TextView mTvFocusPeopleCrimeType;
    @BindView(R.id.tv_focus_people_dynamicInfo)
    TextView mTvFocusPeopleDynamicInfo;
    @BindView(R.id.iv_focus_people_dynamicInfo_from)
    ImageView mIvFocusPeopleDynamicInfoFrom;
    @BindView(tv_focus_people_dynamicInfo_from)
    TextView mTvFocusPeopleDynamicInfoFrom;
    @BindView(R.id.iv_focus_people_media)
    ImageView mIvFocusPeopleMedia;
    @BindView(R.id.iv_focus_people_dynamicInfo_to)
    ImageView mIvFocusPeopleDynamicInfoTo;
    @BindView(R.id.tv_focus_people_dynamicInfo_to)
    TextView mTvFocusPeopleDynamicInfoTo;
    @BindView(R.id.ll_focus_people_attention)
    LinearLayout mLlFocusPeopleAttention;
    @BindView(R.id.ll_focus_people_tel)
    LinearLayout mLlFocusPeopleTel;
    @BindView(R.id.lv_focus_people_track)
    ListView mLvFocusPeopleTrack;
    @BindView(R.id.tv_guanzhu)
    TextView tvGuanzhu;
    private FocusPeopleInfo mPeopleInfo;
    private List<DynamicInfo> dynamicList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_focus_people_detail);
        ButterKnife.bind(this);
        initData();
        initViews();

    }

    @Override
    protected void initViews() {
        super.initViews();
        mTvFocusPeopleCrimeType.setText("涉防");
        tvGuanzhu.setText("取消关注");
        switch (mPeopleInfo.getName()){
            case "张三":
                mIvFocusPeoplePhoto.setImageResource(R.drawable.people1);
                break;
            case "张婷":
                mIvFocusPeoplePhoto.setImageResource(R.drawable.people2);
                break;
            case "王国华":
                mIvFocusPeoplePhoto.setImageResource(R.drawable.people3);
                break;
        }
        mTvFocusPeopleName.setText(mPeopleInfo.getName());
        mTvFocusPeopleTime.setText(mPeopleInfo.getOnTime());
        mTvFocusPeopleSex.setText(mPeopleInfo.getSex());
        mTvFocusPeopleNation.setText(mPeopleInfo.getNation());
        mTvFocusPeopleIdNum.setText(mPeopleInfo.getIdNum());
        mTvFocusPeopleLocation.setText(mPeopleInfo.getLocation());
        mTvFocusPeopleCrimeType.setText(mPeopleInfo.getCrimeType());
        mTvFocusPeopleDynamicInfoFrom.setText(mPeopleInfo.getFrom());
        mTvFocusPeopleDynamicInfoTo.setText(mPeopleInfo.getTo());


        CommonAdapter<DynamicInfo> adapter = new CommonAdapter<DynamicInfo>(this,
                R.layout.item_focus_people_travel, dynamicList) {
            @Override
            protected void convert(ViewHolder holder, DynamicInfo dynamicInfo, int position) {
                if (!TextUtils.isEmpty(dynamicInfo.getFrom())) {
                    holder.setVisible(R.id.ll_focus_people_travel_fromTo, true);
                    holder.setVisible(R.id.ll_focus_people_travel, false);
                    holder.setText(R.id.tv_focus_people_dynamicInfo_from, dynamicInfo.getFrom());
                    holder.setText(R.id.tv_focus_people_dynamicInfo_to, dynamicInfo.getTo());
                } else {
                    holder.setVisible(R.id.ll_focus_people_travel, true);
                    holder.setVisible(R.id.ll_focus_people_travel_fromTo, false);
                    holder.setText(R.id.tv_focus_people_dynamicInfo_travel, dynamicInfo.getLocation());
                }

                holder.setText(R.id.tv_focus_people_travel_date, dynamicInfo.getDate());
                holder.setText(R.id.tv_focus_people_travel_time, dynamicInfo.getTime());
            }
        };

        mLvFocusPeopleTrack.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        super.initData();
        mPeopleInfo = (FocusPeopleInfo) getIntent().getSerializableExtra("positionData");
        dynamicList = new ArrayList();
//       for (int i = 0; i < 10; i++) {
//           DynamicInfo info = null;
//            if (i % 3 == 0) {
//                info = new DynamicInfo("动态信息",
//                       "天津", "北京", "", "2017/8/7", "4:00");
//          } else {
//               info = new DynamicInfo("动态信息",
//                       "", "", "在天津路格林豪泰酒店离店", "2017/7/9", "15:00");
//           }

        DynamicInfo info = new DynamicInfo("动态信息", "天津", "北京", "", "2017/7/7", "16:00");
        DynamicInfo info1 = new DynamicInfo("动态信息", "", "", "在天津路格林豪泰酒店离店", "2017/7/7", "9:00");
        DynamicInfo info2 = new DynamicInfo("动态信息", "", "", "在天津路格林豪泰酒店离店和吴xx一起入住", "2017/6/14", "23:00");
        DynamicInfo info3 = new DynamicInfo("动态信息", "", "", "在天津站地铁站被警察王x核查", "2017/6/14", "20:00");
        DynamicInfo info4 = new DynamicInfo("动态信息", "大连", "天津", "", "2017/6/14", "12:00");
        DynamicInfo info5 = new DynamicInfo("动态信息", "", "", "在大连站被警察吴x核查", "2017/5/22", "22:00");
        DynamicInfo info6 = new DynamicInfo("动态信息", "合肥", "大连", "", "2017/5/22", "16:00");
        DynamicInfo info7 = new DynamicInfo("动态信息", "", "", "在合肥建设东路如家宾馆离店", "2017/5/22", "9:00");
        DynamicInfo info8 = new DynamicInfo("动态信息", "", "", "在合肥建设东路如家宾馆入住", "2017/4/1", "22:00");
        DynamicInfo info9 = new DynamicInfo("动态信息", "", "", "在合肥站被警察刘xx核查", "2017/4/1", "16:00");
        DynamicInfo info10 = new DynamicInfo("动态信息", "天津", "北京", "", "2017/7/7", "16:00");
        dynamicList.add(info);
        dynamicList.add(info1);
        dynamicList.add(info2);
        dynamicList.add(info3);
        dynamicList.add(info4);
        dynamicList.add(info5);
        dynamicList.add(info6);
        dynamicList.add(info7);
        dynamicList.add(info8);
        dynamicList.add(info9);
        dynamicList.add(info10);
//        }
    }
}
